import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String a = in.next();
		String b = in.next();
		in.close();
		
		int lena = a.length();
		int lenb =b.length();
		
		int[][] f = new int[lena+1][lenb+1];
		
		for (int i=1;i<=lena;i++){
			for(int j=1;j<=lenb;j++){
				if(a.charAt(i-1) == b.charAt(j-1))
					f[i][j] = f[i-1][j-1]+1;
				else 
					f[i][j] = Math.max(f[i][j-1],f[i-1][j]);
			}
		}
		
		System.out.println(f[lena][lenb]);

	}

}
